package com.cogent.dynamicform.form.impl;

import java.util.HashMap;

import com.cogent.business.helper.HtmlUIHelper;
import com.cogent.common.util.MapUtil;
import com.cogent.common.util.StringUtil;
import com.cogent.dynamicform.domain.BaseFormColumnDomain;
import com.cogent.dynamicform.domain.FormColumnDomain;
import com.cogent.dynamicform.form.AbstractDynamicForm;
import com.cogent.expression.facade.ExpressionFacade;

public class DateTimeDynamicFormImpl extends AbstractDynamicForm {
	public String genQueryField(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		return "";
	}
	
	public String genInputField(FormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getViewmodel() > 0)
			return getShowValue(formColumnDomain, formMap) + "&nbsp;";
		String date = MapUtil.getLongDate(formMap, formColumnDomain.getName());
		if(StringUtil.isEmpty(date))
			date = ExpressionFacade.getExpressionValue(formMap, formColumnDomain.getExpression());
		boolean isenable = true;
		if(formColumnDomain.getShowcontrol().indexOf("readonly") >= 0)
			isenable = false;
		//return HtmlUIHelper.genDateInput(formColumnDomain.getName(), date, formColumnDomain.isIsrequired(), "(YYYY-MM-DD)");
		return HtmlUIHelper.genDateInputCalendar(formColumnDomain.getName(), date, formColumnDomain.isIsrequired(), "", isenable);
	}
	
	public String getShowValue(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getShowtype() == 1)
			return "&nbsp;";
		String name = formColumnDomain.getName();
		if(name.indexOf(".") > 0)
			name = name.substring(name.indexOf(".") + 1);
		String ret = MapUtil.getLongDate(formMap, name);
		if(StringUtil.isEmpty(ret))
			ret = "&nbsp;";
		return ret;
	}
}
